// components/menuBar/menuBar.ts
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    renderArr: [
      {
        id: 1,
        iconfont: 'wap-home-o',
        text: "首页",
        specialStyle: false,
        isActive: true,
        link: 'home'
      },
      {
        id: 2,
        iconfont: 'shop-o',
        text: "店铺",
        specialStyle: false,
        isActive: false,
        link: 'shop'
      },
      {
        id: 3,
        iconfont: 'plus',
        specialStyle: true,
        isActive: false,
      },
      {
        id: 4,
        iconfont: 'notes-o',
        text: "订单",
        specialStyle: false,
        isActive: false,
        link: 'order'
      },
      {
        id: 5,
        iconfont: 'contact',
        text: "我的",
        specialStyle: false,
        isActive: false,
        link: 'about'
      }
    ],
    currentTarget: null
  },

  /**
   * 组件的方法列表
   */
  methods: {
    changeFunctionFn(e: any) {
      const id = e.currentTarget.dataset.id;
      const arr = [...this.properties.renderArr]
      if (id == this.properties.currentTarget) {
        return;
      }
      arr.forEach(item => {
        if (item.id == id) {
          item.isActive = true
        } else {
          item.isActive = false
        }
      })
      this.setData({
        renderArr: arr,
        currentTarget: id
      })
      const link = e.currentTarget.dataset.link;
      wx.reLaunch({
        url: `../${link}/${link}`,
        fail(err) {
          console.log(err)
        }
      })
    }
  }
})
